package com.example.direct.config;


import org.springframework.amqp.core.*;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

/**
 * ClassName:RabbitConfig
 * Package:com.example.direct.config
 * Description:
 *
 * @Author:ZhangXin
 * @Create:2023/8/11-15:16
 * @Version:v1.0
 */
@Configuration
//@ConfigurationProperties(prefix = "my")
public class RabbitConfig {

    //交换机的名字
    @Value("${my.exchangeName}")
    private String exchangeName;

    //队列A的名字
    @Value("${my.queueAName}")
    private String queueAName;

    //队列B的名字
    @Value("${my.queueBName}")
    private String queueBName;

    //定义交换机
    @Bean
    public DirectExchange directExchange() {
        return ExchangeBuilder.directExchange(exchangeName).build();
    }

    //定义队列
    @Bean
    public Queue queueA() {
        return QueueBuilder.durable(queueAName).build();
    }

    @Bean
    public Queue queueB() {
        return QueueBuilder.durable(queueBName).build();
    }

    //绑定交换机和队列关系
    @Bean
    public Binding bindingA(DirectExchange directExchange, Queue queueA) {
        return BindingBuilder.bind(queueA).to(directExchange).with("error");
    }

    @Bean
    public Binding bindingB1(DirectExchange directExchange, Queue queueB) {
        return BindingBuilder.bind(queueB).to(directExchange).with("info");
    }

    @Bean
    public Binding bindingB2(DirectExchange directExchange, Queue queueB) {
        return BindingBuilder.bind(queueB).to(directExchange).with("error");
    }

    @Bean
    public Binding bindingB3(DirectExchange directExchange, Queue queueB) {
        return BindingBuilder.bind(queueB).to(directExchange).with("warning");
    }


}
